package org.elsfs.cloud.common.mybatis.ext.sql.support.condition;


import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.sql.SqlParameterManager;
import org.elsfs.cloud.common.util.lang.NamingCase;

/**
 * 字段值条件
 *
 */
@RequiredArgsConstructor
public class FieldValueConditionItem implements ConditionItem {

    /**
     * SQL参数管理器
     */
    private final SqlParameterManager sqlParameterManager;
    /**
     * 左边字段名称
     */
    private final String leftField;
    /**
     * 右边字面量值
     */
    private final Object rightValue;
    /**
     * 条件操作符
     */
    private final CompareOperator compareOperator;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return NamingCase.toUnderlineCase(this.leftField) + this.compareOperator.getOperator() + SqlParameterManager.buildParameterPlaceholder(
            this.sqlParameterManager.registerParameter(this.rightValue)
        );
    }
}
